                     Packet Excalibur v1.0.1 (Vivienne release)                  
         
         A multi-platform graphical and scriptable network packet engine
                with extensible text based protocol descriptions
                
                             C o d i n g   : Jitsu
                             I d e a s     : Jitsu & Irib
                             S u p p o r t : Nono                             
         

                    P r o t o c o l s  d e f i n i t i o n s  h e l p



         1) How it works
         2) Semantic
         3) Linking definitions
         4) Adding custom functions
         5) Known limitations


1) How it works

  The rule of thumb behind this project is that network communication is done
  via a set of protocols that work one atop of each other : for instance the ethernet
  protocol describes how to exchange data on a physical "ether network", then you
  may choose IPX or IP to transfer data from one ethernet to the other, and so on..

  Protocols are just a bunch of data organized in fields. A network packet can be
  viewed as the sum of all protocols values it is made off.
  
  Each protocol rises in complexity and further virtualize data from the actual
  physical medium. Hence an organisation (IETF) has designed 7 layers of virtualization
  from the physical wire (level 1) to the actual application (level 7). We refer to these
  as "rfc".
  
  It is assumed that two protocols of the same layer are mutually exclusive (you may not
  send ethernet AND token ring data in the same frame). Sometimes a protocol may have
  optional fields, we refer to these as "rfc_option".
  
  Supposedly protocol from two different layers are independant one from the other : you
  may send IP datagrams over Ethernet or TokenRing all the same. Also, each protocol must
  hold a field that somehow specifies what will be the next protocol level in the packet.
  We use this property to decide which "rfc" to add when building/decoding a packet.
  
  For example the starting point is the iso-1 rfc description file that shows what physical
  network adapter you have, and let you decide which is the next layer to your packet :
  
   file iso\iso-1.def
   
   # This file should not be edited, unless you add new Data Link Types or 
   # Link Types rfc's. Do not rename this file, it is hardcoded into the program.
   
   $byte=1 	$desc="Data Link Type"
    $value=0	$desc=unknown
    $value=1	$desc=ethernet 		$rfc="iso-2 Ethernet.def"
    $value=2	$desc="ethernet 3Mb"	$rfc="iso-2 Ethernet.def"
    $value=3	$desc=AX.25
    $value=4	$desc="token ring"
    $value=5	$desc=chaos
    $value=6	$desc=802.3             $rfc="iso-2 802.3.def"  
    $value=7	$desc=arcnet
    $value=8	$desc=slip
    $value=9	$desc=ppp
    $value=10	$desc=fddi
    $value=11	$desc=atm
    $value=12	$desc=raw		$rfc="iso-2 Ethernet.def"
    $value=13	$desc="bsd slip"
    $value=14	$desc="bsd ppp"

  this reflects the fact that your network adapter internally holds a 1 byte value that sets 
  its "Data Link Type", if of type 1 (ethernet), then the next "rfc" linked will be 
  "iso-2 Ethernet.def". Let's see what fields are found in the Ethernet protocol :
  
   file iso\iso-2 Ethernet.def
   
   $byte=3 $desc="Dst vendor"
    $function=@my-hdw-vendor  $desc="this adapter vendor"
    $function=@hdw-from-iso3 $desc="match iso-3 src.address"
    $value="0xFF 0xFF 0xFF"   $desc="broadcast" 
    $value="0x00 0x00 0x00"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x01"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x02"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x03"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x04"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x05"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x06"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x07"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x08"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x09"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x0A"   $desc="OMRON TATEISI ELECTRONICS CO."
    $value="0x00 0x00 0x0B"   $desc="MATRIX CORPORATION"
    $value="0x00 0x00 0x0C"   $desc="CISCO SYSTEMS, INC."
    #they are actually more values here in the file ...
    $value="0xFF 0xFF 0xFF"   $desc="broadcast"
     
   $byte=3 $desc="Dst Address"
    $function=@my-hdw-addr   $desc="this adapter addr"
    $function=@hdw-from-iso3 $desc="match iso-3 src.addr"
    $value="0xFF 0xFF 0xFF"  $desc="broadcast"
   
   $byte=3 $desc="Src vendor"
    $function=@my-hdw-vendor  $desc="this adapter vendor" 
    $function=@hdw-from-iso3 $desc="match iso-3 dst.addr"
    $value="0xFF 0xFF 0xFF"   $desc="broadcast"
    $value="0x00 0x00 0x00"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x01"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x02"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x03"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x04"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x05"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x06"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x07"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x08"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x09"   $desc="XEROX CORPORATION"
    $value="0x00 0x00 0x0A"   $desc="OMRON TATEISI ELECTRONICS CO."
    $value="0x00 0x00 0x0B"   $desc="MATRIX CORPORATION"
    $value="0x00 0x00 0x0C"   $desc="CISCO SYSTEMS, INC."
    #they are actually more values here in the file ...
    $value="0xFF 0xFF 0xFF"   $desc="broadcast"
    
   $byte=3 $desc="Src Address"
    $function=@my-hdw-addr   $desc="this adapter addr" 
    $function=@hdw-from-iso3 $desc="match iso-3 dst.addr"
    $value="0xFF 0xFF 0xFF"   $desc="broadcast"
   
   $byte=2 $desc="Protocol type" $default=0x0800
    $function=@802-3-len $desc="physical length"  $rfc="iso-2 802.3 Ether.def"
    $value=0x0800 $desc="IP"                      $rfc="iso-3 Internet Protocol (IP).def"                       
    $value=0x0801 $desc="X.75 Internet"
    $value=0x0802 $desc="NBS Internet"
    $value=0x0803 $desc="ECMA Internet"
    $value=0x0804 $desc="CHAOSnet"
    $value=0x0805 $desc="X.25 Level 3"
    $value=0x0806 $desc="Ether ARP"               $rfc="iso-3 Address Resolution (ARP).def"
    $value=0x0807 $desc="XNS Compatibility"
    $value=0x0A00 $desc="Xerox 802.3 PUP"
    $value=0x0A01 $desc="Xerox 802.3 PUP Addr.Trans"
    $value=0x4242 $desc="PCS Basic Block"
    $value=0x0835 $desc="Ether RARP"              $rfc="iso-3 Reverse Addr Rslv (RARP).def"
    $value=0x8037 $desc="IPX"                     $rfc="iso-3 Inter-Packet Xchg (IPX).def"
    $value=0x809B $desc="EtherTalk"
    $value=0x80D5 $desc="IBM SNA"
    $value=0x80F3 $desc="AppleTalk ARP"
    $value=0x8137 $desc="Novell old IPX"          $rfc="iso-3 Inter-Packet Xchg (IPX).def"
    $value=0x814C $desc="SNMP over Ethernet"
    $value=0x8191 $desc="NetBIOS/NetBEUI/SMB"
    $value=0x0801 $desc="Microsoft convoy"
    $value=0x086F $desc="Microsoft LB"
    $value=0x86DD $desc="IP next generation"      $rfc="iso-3 IPnxt.generation (IPng).def"
    $value=0x8870 $desc="Jumbo Packets"

  this reflects the Ethernet header fields as described in IETF ISO RFC "Ethernet" document,
  the last field set to 2 byte length decides for the next protocol, the function @802-3-len
  would mean that this is a 802.3 Ethernet frame, probably for IPX communication, when computed
  it will hold the physical length of the packet. This is permitted due to the fact that the
  maximum physical length of an Ethernet frame is 1535 bytes (0x5FF), and the fixed length
  protocol values starts at 0x800 (IP protocol).
  
  When decoding a packet captured on the wire, we process it through each matching "rfc",
  including functions checks, halt when the data length doesn't match the requierments for
  an additional "rfc", or when we couldn't find a matching "rfc", exess data is shown as
  "unknown".

  Note that in all instance, data is treated in "Network byte order" : from left to right :
  when in a description an 8bit value is divided into bits chunks, the first bits refers to
  the leftmost position in the byte and so on.

2) Semantic

  A protcol definition file must end with the .def extension.
  
  All definition files are stored in a single place (usually "\iso").
  
  A protocol definition is valid only if the sum of all its elements size is a multiple of 8bits.
 
  Comments are outlined by the # sign, anything afther that sign is discarded

  A protocol is divided into fields (or elements), below is a field template, compulsory items 
  are shown between [], optional one are shown between {} :
  
   [[type]=[size]] {element description} {default value}
    { {value=[value set]} {value description} {value defines rfc {rfc an option to current iso}} }

  Let's see in details each of these items :
  
  [type] this can be either :
  
   $byte : some bytes noted in hexadecial or decimal (up to 32 bits length)
   $bit : some bits noted in hexadecimal or decimal (up to 32 bits length)
   $dotted : some bytes noted in dotted decimal form (xx.xx.xx.xx ...)
   $string : some string noted between double quotes ("?????")
   $unicode : some string noted between quotes where white spaces are replaced by 0x00
   
  [size] this can be either :
  
   A positive integer

   0, in this case the field will be of variable size and the protocol is only used to build
   packets, but canno't serve to match one (the field size is unpredictable).

   -x, where x refers to a relative field above in the protocol, this refered field will 
   automagically be assigned the function "size-of" that values the size of the current field.
   See below :
   
    file iso\iso-3 IP Options
    
    $byte=1 $desc="Option code"
     $value=0x07 $desc="Record Route"
     $value=0x44 $desc="Timestamp"
     $value=0x83 $desc="Loose Source Route"
     $value=0x88 $desc="Strict Source Route"
    
    $byte=1 $desc="Length in bytes"
    
    $bit=4 $desc="Overflow"
     $value=0 $desc="no tmstp overflow"
    
    $bit=4 $desc="List ptr/OF FL"
     $value=0 $desc="tmstp : record only"
     $value=1 $desc="tmstp : each rtr records"
     $value=2 $desc="tmstp : rtr record match only" 
     $value=4 $desc="route : has 1st element below"
    
    $byte=-3 $desc="Option data"
    #this last field size will be stored in the "Length in bytes" element above

   +x, same as for -x except that when the size field preceeds the values it may be used to
   build and decode a packet, whereas here it is only usefull to build the packet because it's
   position is unpredictable in a random sniffed packet. In fact this trick is solely used for
   encrypted data : see "iso-3-n Encap Sec Payload.def".

  {element description} is noted :
  
   $desc="<description>"
  
  where the description is used in the "ISO decode" screen, an canno't execeed 40 characters

  {default value} is noted :
  
   $default=[value set]
   
  that default value will be presented to the user on the ISO screen as a default choice for
  that field when he builds a packet. The [value set] must match one defined for that field,
  see below.
  
  {value=[value set]} is noted as :
  
   $value=0x12345678 #32 bits max for a single hexadecimal value
   #or
   $value="0x12 0x34 0x56 0x78"
   #or
   $value=99999999 #32 bits max in decimal notation
   #or
   $value="a b c d e f" #string or unicode style
   #or
   $value=255.255.255.255 #dotted decimal style
   
   special (pre-coded) functions may also be set such as :
   
   $function=@ip-opt-len #the @ sign is used as a function prototype
   
   If you wish to add custom built functions to your protocol see point (4) below.
   Although a field length may be of virtually any size, if you wish to predefine values for
   it, it must no exceed 6 bytes in length. Remember that setting values is not needed unless
   it is meaningfull to the decode part, or would define the next "rfc".
  
  {value description}
  
   $desc="<description>"
  
  where the description is used in the "ISO decode" screen, an canno't execeed 40 characters

3) Linking definitions

  {value defines rfc}, when a pre-defined field element value sets for the next protocol, as
  for instance :
  
    $byte=1 	$desc="Data Link Type"
      $value=0	$desc=unknown
      $value=1	$desc=ethernet 		$rfc="iso-2 Ethernet.def"

  here, the value 1 of "Data Link Type" sets next "rfc" to "iso-2 Ethernet.def". We write :
  
   $rfc="<iso file name>.def"
   
  to tell the program to load <iso file name> as out next protocol. You may wonder what happens
  when a single <file>.def may be called for more than one other protocol layer, don't worry
  the Excalibur works as expected :-) Build for instance an "ICMP option error" packet and see
  how it works ...

  {rfc an option to current iso}, sometimes on the same protocol layer you may find one field
  that sets the next protcol, and another field that sets options to the current protocol layer.
  For that purpose you will add a tag :
  
   $rfc_option
   
  on the same line than the "rfc" item, to tell the program : this is a option to the current
  layer. In this case hitting the "add iso" button on the "ISO decode" screen will first add
  your optional fields, and hitting the button another time will add the next protocol (unless
  your optional field has options itself : all optional items are added first). Build an IP
  packet with options and a TCP payload as an example.

4) Adding custom functions

  If you wish to add custom functions to your protocol, it is (fairly) easy : all you need is
  to add your function to the "\pluggin\addons.c" source file and rebuild the code (see README).
  
  You will also have to add your function declaration to the "ex_functions_table[]" found 
  in addons.c.
  
  Forgive me for the short details here, but again it should be pretty straight-forward if you
  look at the code already there. Also note that I **might** add loadable module (real pluggin)
  functionality in future release.
 
  And oh yeah, don't reinvent the wheel :-) Here are some functions (taken from 
  \globals\globfunc.c) you might find usefull to work with network streams, network 
  byte ordered, again see addons.c for a sample use of those :
 
    void set_bytes_in_stream(uint8 *bytes,uint8 *stream,uint16 start_pos,uint16 length);
    void set_bytes_from_stream(uint8 *bytes,uint8 *stream,uint16 start_pos,uint16 length);
    int cmp_bytes_with_stream(uint8 *bytes,uint8 *stream,uint16 start_pos,uint16 length);

5) Known limitations
         
  The way we define protocols is, hopefully, good enough to describe most protocols. Yet, some
  devised notoriously problematic things such as :
  
   - The number of TCP option fields is sometime linked to the actual size set for that field.
   For now we're only able to simply describe for 1 TCP option at a time.
   
   - Novell signed NCP packets insert an additional field that breaks the protocol independance
   rule. Excalibur won't decipher those properly.
   
  Don't worry, we are working on some extensions to the protocol definition scheme to work around
  those... Keep tuned !
